package com.haizhi.crm.biz.query;

import com.haizhi.crm.biz.model.UserModuleDetailVo;
import com.haizhi.crm.sys.configure.dao.ModuleDao;
import com.haizhi.crm.sys.configure.dao.UserModuleDao;
import com.haizhi.crm.sys.configure.model.ModuleDo;
import com.haizhi.crm.sys.configure.model.UserModuleSettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wangshan on 2018/6/19.
 */
@Service
public class QueryEngine {

    @Autowired
    private UserModuleDao userModuleDao;

    @Autowired
    private ModuleDao moduleDao;

    private Map<String, QueryModel> QUERY_POOL = new HashMap<>();


    public UserModuleDetailVo query(UserModuleSettingVo userModuleSettingVo) {
        ModuleDo moduleDo = moduleDao.findOne(userModuleDao.findOne(userModuleSettingVo.getUserModuleId()).getModuleId());
        QueryModel queryModel = QUERY_POOL.get(moduleDo.getName());
        return queryModel.query(userModuleSettingVo);
    }

    public void register(String name, QueryModel queryModel) {
        QUERY_POOL.put(name, queryModel);
    }


}
